# This file is part of The Vu Toolkit.
#
# The Vu Toolkit is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# The Vu Toolkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with The Vu Toolkit; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
#
# Copyright © Zak Fenton 2008
#

module Vu::SVG

	# A numeric value with units attached (percent, centimeters, pixels, etc.).
	# attr_* style methods relating to Abstract values are defined in Node.
	class Abstract
		# Numerical value
		attr_reader :value
		
		# Units of that value
		attr_reader :units
		
		# Creates an abstract - "12cm"->Abstract.new(12,:cm), "33"->33
		def self.parse (s)
			ss = s.scan(/\d+|\D+/)
			v = ss[0].to_f
			
			if ss.length == 1
				v
			elsif ss[1] == "cm"
				Abstract.new(v,:cm)
			elsif ss[1] == "%"
				Abstract.new(v,:pc)
			else
				v
			end
		end
		
		# Creates an Abstract with given value and units. Valid units are currently:
		#  * -:pc- for percent (%)
		#  * -:px- for pixels
		#  * -:in- for inches
		def initialize (v,u=:px)
			@value = v
			@units = u
		end
	end
end
